home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 17938 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.7 KB

  1. Path: kbad.eglin.af.mil!rpi!not-for-mail
  2. From: brandon@criterion.com (Brandon Wallace)
  3. Newsgroups: comp.lang.c++,comp.lang.c++.moderated
  4. Subject: Re: Help with IOStreams needed!
  5. Date: 17 Apr 1996 19:02:34 -0000
  6. Organization: Nicholas|Applegate Capital Management, San Diego, CA
  7. Sender: cppmods@netlab.cs.rpi.edu
  8. Approved: Dietmar.Kuehl@uni-konstanz.de
  9. Message-ID: <4l3f8a$9mu@netlab.cs.rpi.edu>
  10. References: <4kupd8$khj@netlab.cs.rpi.edu>
  11. NNTP-Posting-Host: netlab.cs.rpi.edu
  12. X-Original-Date: 17 Apr 1996 17:28:41 GMT
  13.  
  14. In article <4kupd8$khj@netlab.cs.rpi.edu>,
  15.     vm@panix.com (Victor Muslin) writes:
  16. -> I am new to IOStreams, so please pardon if this is a silly question...
  17. -> 
  18. -> I open a file as an ofstream. When I write to it I would like to lock it to
  19. -> ensure that no other process can write until I am done. In C I could've used
  20. -> an flock() to which I would pass a file descriptor obtained from open(). How
  21. -> do I do I find the file descriptor associated with an ofstream (or ostream for
  22. -> that matter)? Or, is there a better way to lock an output stream in C++?
  23.  
  24. On my flavor of C++ (solaris2.4/SparcCompiler 4.0), you can do:
  25.  
  26.     ofstream file ("filename");
  27.     file.rdbuf()->fd()
  28.  
  29. to get the file descriptor.
  30. -- 
  31.                       Brandon Wallace
  32.             Nicholas | Applegate Capital Management
  33.                 mailto:bman@houston.nacm.com
  34.         http://www.houston.nacm.com/home-pages/brandon
  35.           "I live life face down in the fast lane."
  36.  
  37.  
  38.       [ Articles to moderate: mailto:c++-submit@netlab.cs.rpi.edu ]
  39.       [  Read the C++ FAQ: http://www.connobj.com/cpp/cppfaq.htm  ]
  40.       [  Moderation policy: http://www.connobj.com/cpp/guide.htm  ]
  41.       [      Comments? mailto:c++-request@netlab.cs.rpi.edu       ]
  42.